package nowCoder;

import java.util.ArrayList;

/**
 * 网易有道
 * 将字符串中的*替换成0或1，输出所有可能。
 * @author Ghost
 *
 */
public class Print {
	private void search(char[] ch, int begin, ArrayList<String> rStrings){
		if(begin==ch.length){
			String rstString = "";
			for(char c:ch){
				rstString+=c;
			}
			rStrings.add(rstString);
		} else{
			ch[begin] = '0';
			int i=begin+1;
			for(;i<ch.length && ch[i]!='*';i++);
			search(ch, i, rStrings);
			ch[begin] = '1';
			search(ch, i, rStrings);
			ch[begin] = '*';
		}
	}
	ArrayList<String> print(String str){
		char[] ch = str.toCharArray();
		int begin=0;
		for(;begin<ch.length && ch[begin]!='*';begin++);
		ArrayList<String> rStrings = new ArrayList<String>();
		search(ch, begin, rStrings);
		return rStrings;
	}
	
	public static void main(String[] args){
		Print print = new Print();
		ArrayList<String>	rStrings = print.print("***");
		System.out.println(rStrings);
	}
}
